import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/routes/routes.dart';
import 'package:sainbainu/common/values/colors.dart';

import 'index.dart';

class SettingsPage extends GetView<SettingsController> {
  const SettingsPage({Key? key}) : super(key: key);

  /// 分割线
  Widget _buildDivider() {
    return const Divider(
      height: 0,
      indent: 16,
      endIndent: 16,
      thickness: 0.5,
      color: AppColors.border,
    );
  }

  // 菜单每一项
  Widget _buildCellItem({
    required String title,
    TextAlign? textAlign = TextAlign.left,
    bool showArrow = true,
    void Function()? onTap,
  }) {
    return ListTile(
      title: Text(title, textAlign: textAlign),
      trailing: showArrow ? const Icon(Icons.keyboard_arrow_right) : null,
      tileColor: Colors.white,
      enableFeedback: true,
      contentPadding: const EdgeInsets.symmetric(horizontal: 16),
      onTap: onTap,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SettingsController>(
      init: SettingsController(),
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: Text("设置".tr)),
          body: ListView(
            padding: const EdgeInsets.all(0),
            children: [
              // _buildCellItem(
              //   title: '我的钱包'.tr,
              //   onTap: () => Get.toNamed(AppRoutes.wallet),
              // ),
              // _buildDivider(),
              // _buildCellItem(
              //   title: '直播记录'.tr,
              //   onTap: () => Get.toNamed(AppRoutes.liveRecord),
              // ),
              // _buildDivider(),
              _buildCellItem(
                title: '编辑资料'.tr,
                onTap: () => Get.toNamed(AppRoutes.userInfo),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '账号与安全'.tr,
                onTap: () => Get.toNamed(AppRoutes.accountSecurity),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '消息通知'.tr,
                onTap: () => Get.toNamed(AppRoutes.notice),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '多语言'.tr,
                onTap: () => Get.toNamed(AppRoutes.language),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '用户反馈'.tr,
                onTap: () => Get.toNamed(AppRoutes.feedback),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '用户协议'.tr,
                onTap: () => Get.toNamed(AppRoutes.userAgree),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '隐私政策'.tr,
                onTap: () => Get.toNamed(AppRoutes.privacyAgree),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '关于SainBainu'.tr,
                onTap: () => Get.toNamed(AppRoutes.aboutWe),
              ),
              _buildDivider(),
              _buildCellItem(
                title: '版本号'.tr,
                onTap: () => Get.toNamed(AppRoutes.version),
              ),
              const SizedBox(height: 10),
              _buildCellItem(
                title: '退出登录'.tr,
                textAlign: TextAlign.center,
                showArrow: false,
                onTap: () => _.handleLogout(),
              ),
            ],
          ),
        );
      },
    );
  }
}
